/**
 * Advanced Software Engineering - assignment part 1 (monica Farrow)
 * JUnit ConstructorTestCustomer class
 * 
 * Some of the methods in this class have been based on lecture notes provided by
 * Monica Farrow as a part of Software Engineering courses at Heriot-Watt University.
 */

package depotTests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import depot.*;

public class ConstructorTestCustomer {

	private int[] dim1;
	private Parcel pcl;

	/**
	 * Sets up valid Parcel object for use with Customer objects
	 */
	@Before
	public void setUp() {
		dim1 = new int[] {35,35,35};
		pcl = new Parcel("E000112", dim1, 2.55, 2);
	} 

	/**
	 * Test length of customerID
	 * Test 5 chars
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustIDLength1_1() {
		Customer cust = new Customer("00501","Gregor","McCloud",pcl);
	}

	/**
	 * Test length of customerID
	 * Test 5 chars
	 * Test for exception message
	 */
	@Test
	public final void testCustIDLength1_2() {
		try {
			Customer cust = new Customer("00501","Gregor","McCloud",pcl);
			fail("Invalid customerID - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("6 characters"));
		}
	}

	/**
	 * Test length of customerID
	 * Test 7 chars
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustIDLength2() {
		Customer cust = new Customer("0005501","Gregor","McCloud",pcl);
	}

	/**
	 * Test length of customerID
	 * Test 6 chars
	 */
	@Test
	public final void testCustIDLength3() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test customerID is only digits
	 * Test 1 char is 'x'
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustIDAllDigits1_1() {
		Customer cust = new Customer("00x501","Gregor","McCloud",pcl);
	}

	/**
	 * Test customerID is only digits
	 * Test 1 char is 'x'
	 * Test for exception message
	 */
	@Test
	public final void testCustIDAllDigits1_2() {
		try {
			Customer cust = new Customer("00x501","Gregor","McCloud",pcl);
			fail("Invalid customerID - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("only digits"));
		}
	}

	/**
	 * Test customerID is only digits
	 * Test all chars are digits
	 */
	@Test
	public final void testCustIDAllDigits2() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test length of first name
	 * Test 1 char
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustFnameLength1_1() {
		Customer cust = new Customer("000501","G","McCloud",pcl);
	}

	/**
	 * Test length of first name
	 * Test 1 char
	 * Test for exception message
	 */
	@Test
	public final void testCustFnameLength1_2() {
		try {
			Customer cust = new Customer("000501","G","McCloud",pcl);
			fail("Invalid fName length - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("First name must"));
		}
	}

	/**
	 * Test length of first name
	 * Test 16 char
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustFnameLength2() {
		Customer cust = new Customer("000501","Bartholomew Paul","McCloud",pcl);
	}

	/**
	 * Test length of first name
	 * Test 6 chars
	 */
	@Test
	public final void testCustFnameLength3() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test length of first name
	 * Test 2 chars
	 */
	@Test
	public final void testCustFnameLength4() {
		Customer cust = new Customer("000501","Jo","McCloud",pcl);
	}

	/**
	 * Test length of first name
	 * Test 15 chars
	 */
	@Test
	public final void testCustFnameLength5() {
		Customer cust = new Customer("000501","Billy Bob Bryan","McCloud",pcl);
	}

	/**
	 * Test length of last name
	 * Test 1 char
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustLnameLength1_1() {
		Customer cust = new Customer("000501","Gregor","M",pcl);
	}

	/**
	 * Test length of last name
	 * Test 1 char
	 * Test for exception message
	 */
	@Test
	public final void testCustLnameLength1_2() {
		try {
			Customer cust = new Customer("000501","Gregor","M",pcl);
			fail("Invalid lName length - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("Last name must"));
		}
	}

	/**
	 * Test length of last name
	 * Test 16 chars
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustLnameLength2() {
		Customer cust = new Customer("000501","Gregor","Burnelley-Smythe",pcl);
	}

	/**
	 * Test length of last name
	 * Test 7 chars
	 */
	@Test
	public final void testCustLnameLength3() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test length of last name
	 * Test 2 chars
	 */
	@Test
	public final void testCustLnameLength4() {
		Customer cust = new Customer("000501","Gregor","Ho",pcl);
	}

	/**
	 * Test length of last name
	 * Test 15 chars
	 */
	@Test
	public final void testCustLnameLength5() {
		Customer cust = new Customer("000501","Gregor","Burnelley-Smith",pcl);
	}

	/**
	 * Test if first name contains invalid chars
	 * Test contains '@'
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustFnameInvalidChars1_1() {
		Customer cust = new Customer("000501","H@rry","McCloud",pcl);
	}

	/**
	 * Test if first name contains invalid chars
	 * Test contains '@'
	 * Test for exception message
	 */
	@Test
	public final void testCustFnameInvalidChars1_2() {
		try {
			Customer cust = new Customer("000501","H@rry","McCloud",pcl);
			fail("Invalid chars in fName - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("First name contains"));
		}
	}

	/**
	 * Test if first name contains invalid chars
	 * Test contains '-'
	 */
	@Test
	public final void testCustFnameInvalidChars3() {
		Customer cust = new Customer("000501","Jean-Paul","McCloud",pcl);
	}

	/**
	 * Test if first name contains invalid chars
	 * Test contains '
	 */
	@Test
	public final void testCustFnameInvalidChars4() {
		Customer cust = new Customer("000501","Ja'net","McCloud",pcl);
	}

	/**
	 * Test if first name contains invalid chars
	 * Test no invalid chars
	 */
	@Test
	public final void testCustFnameInvalidChars2() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test if last name contains invalid chars
	 * Test contains '0'
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustLnameInvalidChars1_1() {
		Customer cust = new Customer("000501","Harry","McCl0ud",pcl);
	}

	/**
	 * Test if last name contains invalid chars
	 * Test contains '0'
	 * Test for exception message
	 */
	@Test
	public final void testCustLnameInvalidChars1_2() {
		try {
			Customer cust = new Customer("000501","Harry","McCl0ud",pcl);
			fail("Invalid chars in lName - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("Last name contains"));
		}
	}

	/**
	 * Test if last name contains invalid chars
	 * Test no invalid chars
	 */
	@Test
	public final void testCustLnameInvalidChars2() {
		Customer cust = new Customer("000501","Gregor","McCloud",pcl);
	}

	/**
	 * Test if last name contains invalid chars
	 * Test contains space
	 */
	@Test
	public final void testCustLnameInvalidChars3() {
		Customer cust = new Customer("000501","Gregor","De Sousa",pcl);
	}

	/**
	 * Test if last name contains invalid chars
	 * Test contains '
	 */
	@Test
	public final void testCustLnameInvalidChars4() {
		Customer cust = new Customer("000501","Gregor","D'Amour",pcl);
	}

	/**
	 * Test if first name contains only spaces
	 * Test contains only spaces
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustFnameSpaces1_1() {
		Customer cust = new Customer("000501","     ","McCloud",pcl);
	}

	/**
	 * Test if first name contains only spaces
	 * Test contains only spaces
	 * Test for exception message
	 */
	@Test
	public final void testCustFnameSpaces1_2() {
		try {
			Customer cust = new Customer("000501","     ","McCloud",pcl);
			fail("Fname contains only spaces - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("First name contains only"));
		}
	}

	/**
	 * Test if last name contains only spaces
	 * Test contains only spaces
	 * Test for IllegalArgumentException
	 */
	@Test(expected = IllegalArgumentException.class)
	public final void testCustLnameSpaces1_1() {
		Customer cust = new Customer("000501","Harry","      ",pcl);
	}

	/**
	 * Test if last name contains only spaces
	 * Test contains only spaces
	 * Test for exception message
	 */
	@Test
	public final void testCustLnameSpaces1_2() {
		try {
			Customer cust = new Customer("000501","Harry","      ",pcl);
			fail("Lname contains only spaces - should throw exception");
		} catch (IllegalArgumentException e) {
			assertTrue(e.getMessage().contains("Last name contains only"));
		}
	}


}
